<template>
	<view class="content">
		<view class="info_div">

			<view class="item_div">
				<view style="display: flex;">
					<view style="color: red;">*</view>选择平台 |
				</view>
				<view class="et" @click.stop="onSelTms">{{platform.name || '请选择TMS系统'}} ></view>
			</view>

			<view class="item_div_2" style="display: flex;">
				<view style="display: flex;">
					<view style="color: red;">*</view>输入运单 |
				</view>
				<input class="et" placeholder="请输入运单号" @input="onInputOrder" :value="info.platform_order" />
			</view>

		</view>

		<view class="btn_ok" @click.stop="onOk">确定</view>

	</view>
</template>

<script>
	import { getUInfo } from '@/util/util.js'
	export default {
		data() {
			return {

				platform: {}, // TMS平台

				info: {
					order_id: '', // 传过来的订单id
					platform: '', // 平台 cmm qqt
					platform_order: '', // 运单号
				},

				location: {}, // 地理位置对象
			}
		},

		onLoad(opts) {
			if (opts.id) {
				this.info.order_id = opts.id
			}
		},

		mounted() {
			let that = this
			// 事件总线:
			uni.$on('onSelTms', data => {
				console.log('监听事件onSelTms,参数 data =', data);
				that.platform = data.msg
				that.info.platform = that.platform.platform
			})
		},

		methods: {

			// 打开地图选点
			onChooseLocation() {
				uni.chooseLocation({
					success: (res) => {
						console.log('地图选择位置的结果 = ', JSON.stringify(res));
						this.location = res
						this.info.longitude = res.longitude
						this.info.latitude = res.latitude
					},
					fail: (res) => {
						console.log('onChooseLocation.fail = ', JSON.stringify(res));
						uni.showToast({ title: '未获取到位置信息', icon: 'none' })
					}
				})
			},

			// 选择TMS
			onSelTms() {
				uni.navigateTo({ url: '/pages/sys/tms_list' })
			},
			// 输入运单号
			onInputOrder(e) {
				this.info.platform_order = e.detail.value
			},

			// 确认添加
			onOk(flag) {
				let that = this
				if (!this.info.platform) {
					uni.showToast({ icon: 'none', title: '请选择TMS系统' })
					return
				}
				if (!this.info.platform_order) {
					uni.showToast({ icon: 'none', title: '请输入运单号' })
					return
				}
				// console.log('准备绑定的tms数据 = ', this.info);
				uni.showModal({ title: '提示', content: '确认提交？', success: (res) => { res.confirm && that.postData() } })
			},

			// 接口:提交TMS运单号
			async postData() {
				let that = this
				let token = getUInfo().token
				uni.showLoading({ title: '提交中', mask: true, })
				let res = await that.$postPlatform({ token, ...this.info })
				if (res.code == 1) {
					uni.$emit('postPlatform', { msg: 'postPlatform' })
					uni.showModal({ title: '提示', content: `${res.msg}`, showCancel: false, success: (res) => { res.confirm && uni.navigateBack() } })
				} else {
					uni.showToast({ title: res.msg, icon: 'none' })
				}
			},

		}
	}
</script>

<style scoped>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	/* 分割线 */
	.divider {
		width: 100%;
		height: 1rpx;
		background-color: rgba(0, 0, 0, 0.2);
	}

	.info_div {
		display: flex;
		flex-direction: column;
		width: calc(100% - 40rpx);
		margin: 20rpx 20rpx 0 20rpx;
	}

	/* 每个填写项目的容器 */
	.item_div {
		display: flex;
		justify-content: space-between;
		width: 100%;
		height: 60rpx;
		line-height: 60rpx;
		margin: 22rpx 0 0 0;
		font-size: 28rpx;
		/* background-color: red; */
		overflow: hidden;
	}

	/* 大一点的项目容器 */
	.item_div_2 {
		display: flex;
		justify-content: space-between;
		width: 100%;
		height: 100rpx;
		/* line-height: 100rpx; */
		margin: 30rpx 0 0 0;
		font-size: 28rpx;
	}

	/* 预约时间项目的容器 */
	.item_div_3 {
		display: flex;
		justify-content: space-between;
		width: 100%;
		height: 86rpx;
		line-height: 60rpx;
		margin: 22rpx 0 0 0;
		font-size: 28rpx;
		/* background-color: red; */
		overflow: hidden;
	}

	.et {
		/* background-color: red; */
		flex-grow: 1;
		margin: 0 0 0 0rpx;
		max-width: 70%;
		height: 60rpx;
		text-align: right;
		font-size: 28rpx;
		color: #666;
	}

	.et_2 {
		/* background-color: red; */
		flex-grow: 1;
		margin: 0 0 0 0rpx;
		max-width: 70%;
		height: 100rpx;
		/* line-height: 100rpx; */
		text-align: right;
		font-size: 28rpx;
		color: #666;
		/* border: solid 1rpx gray; */
		/* vertical-align: middle; */
	}

	.et_3 {
		display: flex;
		/* background-color: red; */
		flex-grow: 1;
		margin: 0 0 0 0rpx;
		max-width: 70%;
		height: 60rpx;
		font-size: 28rpx;
		color: #666;
		/* background-color: red; */
	}

	.picker_region {
		width: 70%;
		height: 100%;
		text-align: right;
		/* background: red; */
	}

	.btn_ok {
		align-self: center;
		background: #F7D34B;
		width: 90%;
		height: 80rpx;
		line-height: 80rpx;
		text-align: center;
		font-size: 30rpx;
		font-weight: bold;
		margin: 88rpx 0 0 0;
		border-radius: 12rpx;
	}
</style>